package com.lc.ei.utils;

import com.study.common.utils.AliTranslateUtil;
import com.study.common.utils.LcStrUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: some desc
 * @author: LChuang
 * @date: 2023/9/21 13:52
 */
@Slf4j
public class ExcelUtil {

    /**
     * 处理excel数据，形成 标题(英)-->值 的map
     *
     * @param dataList 数据列表
     * @param titleMap 中文标题map
     */
    public static Map<Integer, Map<String, String>> handleData(List<Map<Integer, Map<Integer, String>>> dataList, Map<Integer, String> titleMap) {
        Map<Integer, Map<String, String>> modifyDataMap = new HashMap<>();
        // 翻译列名
        for (Map<Integer, Map<Integer, String>> dataMap : dataList) {
            for (Map.Entry<Integer, Map<Integer, String>> dataEntry : dataMap.entrySet()) {
                Map<String, String> inMap = new HashMap<>();
                for (Map.Entry<Integer, String> entry : dataEntry.getValue().entrySet()) {
                    inMap.put(titleMap.get(entry.getKey()), entry.getValue());
                }
                modifyDataMap.put(dataEntry.getKey(), inMap);
            }
        }
        return modifyDataMap;
    }

    /**
     * 处理excel表头，形成 英文表头map
     * @param titleMap 中文标题map
     */
    public static Map<Integer, String> handleTitle(Map<Integer, String> titleMap) {
        for (Map.Entry<Integer, String> entry : titleMap.entrySet()) {
            String s = LcStrUtil.spaceToHump(AliTranslateUtil.aliTranslate(entry.getValue()));
            entry.setValue(LcStrUtil.handleSpecialCharacter(s));
        }
        return titleMap;
    }

}
